package com.lanou3g.code0423.set;

import java.util.*;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/4/23;
 * Otherwise, I don't know who created it either
 */

public class Test02 {
    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>();

        set.add(1);
        set.add(2);
        set.add(3);
        set.add(4);

        // 获取迭代器
        Iterator<Integer> iterator = set.iterator();
        // 只要迭代器 有下一个元素
        while (iterator.hasNext()) {
            // 从迭代器中取下一个元素
            Integer i = iterator.next();
            if (i % 2 == 0) {
                // 使用迭代器删除元素
                iterator.remove();
            }
            System.out.println(i);
        }
        System.out.println("删除后");
        for (Integer integer : set) {
            System.out.println(integer);
        }



    }
}
